#include <stdio.h>
#include <stdarg.h>
#include <time.h>
#include <string.h>

void log(int level, const char *file, int line, const char *func, const char *format, ...);
#define ANDROID_LOG_ERROR 0
#define LOG_INFO __FILE__,__LINE__,__FUNCTION__
#define LOGE(fmt, ...) log(ANDROID_LOG_ERROR, LOG_INFO, fmt, ## __VA_ARGS__)
#define LOG_BUFF_SIZE 500

char *loglevel_name[] = {
    "ERROR",
    "WARN"
};

#ifdef LOG_LEVEL_1
int logLevel = 1;
#else
int logLevel = 0;
#endif
void log(int level, const char *file, int line, const char *func, const char *format, ...)
{
	if(level < logLevel)
		return;

	char buffer[LOG_BUFF_SIZE] = { 0 };
	va_list arg_list;
	va_start(arg_list, format);
	vsnprintf(buffer, LOG_BUFF_SIZE, format, arg_list);
	va_end(arg_list);

    time_t curtime;
    time(&curtime);
    char* dt = ctime(&curtime);
    dt[strlen(dt)-1]=0;

	printf("[%s %s: %s(%d) %s()]: %s\n", dt, loglevel_name[level], file, line, func, buffer);
}

int main()
{
    LOGE("hello");
    LOGE("world %d", 1);
}